home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir39 / borfix.zip / EMS.PAS < prev    next >
Pascal/Delphi Source File  |  1989-08-28  |  5KB  |  220 lines

  1.   unit ems;
  2.   {*****************************************************}
  3.   {*                                                   *}
  4.   {*                 Expanded Memory Unit              *}
  5.   {*                                                   *}
  6.   {*                    By:MB Software                 *}
  7.   {*                       89/08/29                    *}
  8.   {*                        V. 1.0                     *}
  9.   {*****************************************************}
  10.   {*The unit supports the EMM 3.2+.All functions marked*}
  11.   {*with a plus sign should not be used with the       *}
  12.   {*functions with a minus sign.Of course this will not*}
  13.   {*the system or anything but the functions with a    *}
  14.   {*plus sign use the functions with the negative signs*}
  15.   {*.                                                  *}
  16.   {*Reference:Advanced DOS,BYTE volume 10,#11          *}
  17.   {*By: Michael Hyman,Ray Duncan                       *}
  18.   {*Published by: MIS:PRESS,McGraw-Hill                *}
  19.   {*****************************************************}
  20.   interface
  21.   type
  22.   st5=string[5];
  23.   st=string[3];
  24.   var
  25.   base,handle,pages:word;
  26.   function hex_string(number: word): ST5;
  27.   function emm_driver:word;
  28.   function get_frame(var frame:word): word;
  29.   function unalloc_p(var tp,up:word): word;
  30.   function alloc_page(var handle:word;var page:word): word;{-}
  31.   function map_page(var phys_page,log_page,handle:word): word;{-}
  32.   function dealloc_page(var handle:word): word;{-}
  33.   function version(var v,f:word): word;
  34.   function alloc_all:word;{+}
  35.   function writ_byte(var page,byte,value:word):word;{+}
  36.   function rd_byte(var page,byte:word):word;{+}
  37.   function dealloc_all:word;{+}
  38.   function Get_EMM_handles:word;
  39.   function get_pages_owned_by_handle(var han:word):word;
  40.   implementation
  41.   uses dos;
  42.   Function Hex_String(Number: Word): ST5;
  43.   Function Hex_Char(Number: Word): Char;
  44.   begin
  45.   If Number<10 then Hex_Char:=Char(Number+48) else Hex_Char:=Char(Number+55);
  46.   end;
  47.  
  48.   var
  49.   S: ST5;
  50.   begin
  51.   S:='';
  52.   S:=Hex_Char( (Number shr 1) div 2048);
  53.   Number:=( ((Number shr 1) mod 2048) shl 1)+
  54.         (Number and 1) ;
  55.   S:=S+Hex_Char(Number div 256);
  56.   Number:=Number mod 256;
  57.   S:=S+Hex_Char(Number div 16);
  58.   Number:=Number mod 16;
  59.   S:=S+Hex_Char(Number);
  60.     Hex_String:=S+'h';
  61.   end; { Function Hex_String }
  62. function emm_driver:word;
  63. var
  64. regs:registers;
  65. pos:word;
  66. driver:string[8];
  67. found:string[8];
  68. begin
  69. found:='';
  70. driver:='EMMXXXX0';
  71. with regs do
  72. begin
  73. ah:=$35;
  74. al:=$67;
  75. intr($21,regs);
  76. for pos:=0 to 7 do found:=found+chr(mem[es:pos+$0A]);
  77. emm_driver:=1;
  78. if found<>driver then emm_driver:=0;
  79. end;
  80. end;
  81. function get_frame(var frame:word): word;
  82. var
  83. regs:registers;
  84. begin
  85. with regs do
  86. begin
  87. ah:=$41;
  88. intr($67,regs);
  89. get_frame:=ah;
  90. frame:= bx;
  91. end;
  92. end;
  93. function alloc_page(var handle:word;var page:word):word;
  94. var
  95. regs:registers;
  96. begin
  97. with regs do
  98. begin
  99. ah:=$43;
  100. bx:=page;
  101. intr($67,regs);
  102. handle:=dx;
  103. alloc_page:=ah;
  104. end;
  105. end;
  106. function unalloc_p(var tp,up:word):word;
  107. var
  108. regs:registers;
  109. begin
  110. with regs do
  111. begin
  112. ah:=$42;
  113. intr($67,regs);
  114. up:=bx;
  115. tp:=dx;
  116. unalloc_p:=ah;
  117. end;
  118. end;
  119. function map_page(var phys_page,log_page,handle:word):word;
  120. var
  121. regs:registers;
  122. begin
  123. with regs do
  124. begin
  125. ah:=$44;
  126. al:=phys_page;
  127. bx:=log_page;
  128. dx:=handle;
  129. intr($67,regs);
  130. map_page:=ah;
  131. end;
  132. end;
  133. function dealloc_page(var handle:word): word;
  134. var
  135. regs:registers;
  136. begin
  137. with regs do
  138. begin
  139. ah:=$45;
  140. dx:=handle;
  141. intr($67,regs);
  142. dealloc_page:=ah;
  143. end;
  144. end;
  145. function version(var v,f:word): word;
  146. var
  147. regs:registers;
  148. begin
  149. with regs do
  150. begin
  151. ah:=$46;
  152. intr($67,regs);
  153. if ah=0 then begin
  154. v:=al shr 4 ;
  155. f:=al and $f;
  156. end;
  157. version:=ah;
  158. end;
  159. end;
  160. function alloc_all:word;
  161. var
  162. a,b,c,d,error,frame:word;
  163. begin
  164. error:=get_frame(frame);
  165. if error<>0 then alloc_all:=1;
  166. error:=unalloc_p(a,b);
  167. if error<>0 then alloc_all:=2;
  168. error:=alloc_page(handle,b);
  169. if error<>0 then alloc_all:=3;
  170. pages:=b;
  171. base:=frame;
  172. end;
  173. function rd_byte(var page,byte:word):word;
  174. var
  175. a,b,c,d,error:word;
  176. begin
  177. error:=get_frame(base);
  178. c:=1;
  179. error:=map_page(c,page,handle);
  180. rd_byte:=mem[base:byte];
  181. end;
  182. function writ_byte(var page,byte,value:word):word;
  183. var
  184. a,b,c,d,error:word;
  185. begin
  186. writ_byte:=0;
  187. if page>pages then writ_byte:=3;
  188. c:=0;
  189. error:=map_page(c,page,handle);
  190. if error<>0 then writ_byte:=2;
  191. mem[base:byte]:=value;
  192. end;
  193. function dealloc_all:word;
  194. begin
  195. dealloc_all:=dealloc_page(handle);
  196. end;
  197.  
  198. function get_emm_handles:word;
  199. var
  200. regs:registers;
  201. begin
  202. with regs do begin
  203. ah:=$4b;
  204. intr($67,regs);
  205. end;
  206. end;
  207. function get_pages_owned_by_handle(var han:word):word;
  208. var
  209. regs:registers;
  210. begin
  211. with regs do begin
  212. ah:=$4c;
  213. dx:=han;
  214. intr($67,regs);
  215. get_pages_owned_by_handle:=bx;
  216. end;
  217. end;
  218. end.
  219.  
  220.